package com.gzsxy.esjy.message.handler.impl;

import com.gzsxy.esjy.message.channel.ChannelManager;
import com.gzsxy.esjy.message.handler.IMessageCenterHandler;
import com.gzsxy.esjy.message.netty.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import io.netty.channel.Channel;

/**
 * 订阅处理
 */
@Component(SubscribMessageCenterHandler.CMD)
public class SubscribMessageCenterHandler implements IMessageCenterHandler<String> {

	public final static String CMD = "/subscrib" ;
	
	@Autowired
	private ChannelManager channelManager ;
	
	@Override
	public void handler(String body, Channel channel) {
		channelManager.addChannel(body, channel);
		channel.writeAndFlush(Message.success(String.format("订阅%s成功", body))) ;
	}

	@Override
	public String convert(Object body) {
		return (String) body;
	}
	
}
